package cn.gailvlun.gll.presentation.apartment.room.vm

import android.arch.lifecycle.ViewModel
import cn.gailvlun.gll.chatlib.db.ChatDB2
import cn.gailvlun.gll.net.apartment.room.Room
import io.realm.Realm

class CreateRoomViewModel: ViewModel {

    private var realm: Realm? = null
    var isModify: Boolean = false

    constructor() : super() {
        realm = Realm.getInstance(ChatDB2.getConfiguration())
    }

    fun getRoomById(roomId: Int): Room? {
        return realm!!.where(Room::class.java)
                .equalTo("id", roomId)
                .findFirst()
    }

    override fun onCleared() {
        realm?.close()
        realm = null

        super.onCleared()
    }
}